﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using INTEX.DataBase.Tools;
using ReflectionStudio.Components.UserControls;
using ReflectionStudio.Core.Events;
using ReflectionStudio.Core.Helpers;
using System.Windows;
using System.Windows.Data;
namespace WPFExcelReport
{
    /// <summary>
    /// Interaction logic for ProductionOrder.xaml
    /// </summary>
    public partial class JLTCOST : DocumentBase
    {
        string MANDANT = "",INVOICE = "",VKPAUFKRS = "",VKPAUFLFD = "",VKPKOLL = "",VKPART = "",VAABEZ = "",CONSTRUCTION = "", COLOR = "";
        string YARN = "", MKUNDER = "", KDKNAME = "", TYPE = "", CURRENCY = "", PREH = "", STAFF = "", COMMISSION = "", NEWART = "", REMARK = "";
        int ROWNID = 0;
        double RATE = 0,RAT = 0, WARPDEN = 0, WEFTDEN = 0, VKPQTY = 0, MDELQTY = 0, YDELQTY = 0, WEFTTOT = 0, WARPUSAGE = 0, WARPPRICE = 0, WEFTUSAGE = 0;
        double WEFTPRICE = 0, YARNVALUE = 0, INVVALUE = 0, RMBVALUE = 0, PRODVALUE = 0, OTHERSVALUE = 0, COSTTOT = 0, COSTTOTW = 0;
        double WARPED = 0, WEFTED = 0, DYEVALUE = 0, MCOSTFIN = 0, MCOSTPAKVV = 0, MCOSTFADD = 0, MPRICEAGENT = 0, MCOSTAGENT = 0, MPRICESHIP = 0, MCOSTSHIP = 0;
        double MPRICEFLIGHT = 0, MCOSTFLIGHT = 0, MCOSTADD = 0, MCOSTUNIT = 0, RMBPRICE = 0, MCOSTGROSS = 0, MCOSTNET = 0, TOTVALUE = 0, TOTVALUEW = 0, PRICE = 0;
        string FROMDATE = "", ENDDATE = "", FACTORY = "", CURR = "", NEWUSER = "", NEWTIME = "", CHGUSER = "", CHGTIME = "", DAT = "";
        string INVDAT = "", DELDAT = "",ART = "";
        bool status = false;
        ApplicationBase app
        {
            get
            {
                return ApplicationBase.Instance;
            }
        }
        #region ==ARTP===========
        public static readonly DependencyProperty ARTPProperty = DependencyProperty.Register("ARTP",
            typeof(string), typeof(JLTCOST),
            new FrameworkPropertyMetadata("", FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnARTPChanged));
        public string ARTP
        {
            get
            {
                return (string)GetValue(ARTPProperty);
            }
            set
            {
                SetValue(ARTPProperty, value);
                if (value.Trim().Length==0)
                {
                    #region==初始化界面====
                    txtCOLOR.Text = "";
                    txtYARN.Text = "";
                    txtWEFTDEN.Text = "";
                    txtWARPUSAGE.Text = "";
                    txtWARPPRICE.Text = "";
                    txtWEFTUSAGE.Text = "";
                    txtWEFTPRICE.Text = "";
                    txtYARNVALUE.Text = "";
                    txtWARPED.Text = "";
                    txtWEFTED.Text = "";
                    txtDYEVALUE.Text = "";
                    txtCOSTFIN.Text = "";
                    txtCOSTPAKVV.Text = "";
                    txtCOSTFADD.Text = "";
                    txtAGENT.Text = "";
                    txtSHIP.Text = "";
                    txtFLIGHT.Text = "";
                    #endregion
                }
                else
                {
                    RESET(null, null); 
                    QUERYICC_VKCOST(null, null);  
                    vwCOST.View.MoveCurrentTo(-1);
                }
            }
        }
        private static void OnARTPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as JLTCOST;
            if (src != null)
            {
                src.ARTP = (string)e.NewValue;
            }
        }
        #endregion
        #region ==dwVKP===========
        public static readonly DependencyProperty dwVKPProperty = DependencyProperty.Register("dwVKP",
            typeof(DataRow), typeof(JLTCOST),
            new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OndwVKPChanged));
        public DataRow dwVKP
        {
            get
            {
                return (DataRow)GetValue(dwVKPProperty);
            }
            set
            {
                SetValue(dwVKPProperty, value);
                vwCOST.View.MoveCurrentTo(-1);
            }
        }
        private static void OndwVKPChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e)
        {
            var src = sender as JLTCOST;
            if (src != null)
            {
                src.dwVKP = (DataRow)e.NewValue;
            } 
            if (src.dwVKP == null)
            {
                return;
                #region==初始化界面====
                src.txtCOLOR.Text = "";
                src.txtYARN.Text = "";
                src.txtWEFTDEN.Text = "";
                src.txtWARPUSAGE.Text = "";
                src.txtWARPPRICE.Text = "";
                src.txtWEFTUSAGE.Text = "";
                src.txtWEFTPRICE.Text = "";
                src.txtYARNVALUE.Text = "";
                src.txtWARPED.Text = "";
                src.txtWEFTED.Text = "";
                src.txtDYEVALUE.Text = "";
                src.txtCOSTFIN.Text = "";
                src.txtCOSTPAKVV.Text = "";
                src.txtCOSTFADD.Text = "";
                src.txtAGENT.Text = "";
                src.txtSHIP.Text = "";
                src.txtFLIGHT.Text = "";
                #endregion
            }
            else
            {

                src.RESET(null, null);
                #region====变量，界面赋值=====
                src.MANDANT = src.dwVKP["MANDANT"].ToString().Trim();
                src.VKPAUFKRS = src.dwVKP["VKPAUFKRS"].ToString().Trim();
                src.VKPAUFLFD = src.dwVKP["VKPAUFLFD"].ToString().Trim();
                src.VKPKOLL = src.dwVKP["VKPKOLL"].ToString().Trim();
                src.VKPART = src.dwVKP["VKPART"].ToString().Trim();
                src.VAABEZ = Helpers.Helper.Convert8859P1ToGB2312(src.dwVKP["VAABEZ"].ToString().Trim());
                src.CONSTRUCTION = Helpers.Helper.Convert8859P1ToGB2312(src.dwVKP["CONSTRUCTION"].ToString().Trim());
                src.COLOR = src.dwVKP["COLOR"].ToString().Trim();
                src.YARN = Helpers.Helper.Convert8859P1ToGB2312(src.dwVKP["YARN"].ToString().Trim());
                src.WARPDEN = System.Convert.ToDouble(src.dwVKP["WARPDEN"].ToString().Trim());
                src.WEFTDEN = System.Convert.ToDouble(src.dwVKP["WEFTDEN"].ToString().Trim());
                src.MKUNDER = src.dwVKP["MKUNDER"].ToString().Trim();
                src.KDKNAME = Helpers.Helper.Convert8859P1ToGB2312(src.dwVKP["KDKNAME"].ToString().Trim());
                src.VKPQTY = System.Convert.ToDouble(src.dwVKP["VKPQTY"].ToString().Trim());
                src.TYPE = src.dwVKP["TYPE"].ToString().Trim();
                src.CURRENCY = src.dwVKP["CURRENCY"].ToString().Trim();
                src.PREH = src.dwVKP["PREH"].ToString().Trim();
                src.WARPUSAGE = System.Convert.ToDouble(src.dwVKP["WARPUSAGE"].ToString().Trim());
                src.WARPPRICE = System.Convert.ToDouble(src.dwVKP["WARPPRICE"].ToString().Trim());
                src.WEFTUSAGE = System.Convert.ToDouble(src.dwVKP["WEFTUSAGE"].ToString().Trim());
                src.WEFTPRICE = System.Convert.ToDouble(src.dwVKP["WEFTPRICE"].ToString().Trim());
                src.YARNVALUE = System.Convert.ToDouble(src.dwVKP["YARNVALUE"].ToString().Trim());
                src.WARPED = System.Convert.ToDouble(src.dwVKP["WARPED"].ToString().Trim());
                src.WEFTED = System.Convert.ToDouble(src.dwVKP["WEFTED"].ToString().Trim());
                src.DYEVALUE = System.Convert.ToDouble(src.dwVKP["DYEVALUE"].ToString().Trim());
                src.MCOSTFIN = System.Convert.ToDouble(src.dwVKP["MCOSTFIN"].ToString().Trim());
                src.MCOSTPAKVV = System.Convert.ToDouble(src.dwVKP["MCOSTPAKVV"].ToString().Trim());
                src.MCOSTFADD = System.Convert.ToDouble(src.dwVKP["MCOSTFADD"].ToString().Trim());
                src.MPRICEAGENT = System.Convert.ToDouble(src.dwVKP["MPRICEAGENT"].ToString().Trim());
                src.MCOSTAGENT = System.Convert.ToDouble(src.dwVKP["MCOSTAGENT"].ToString().Trim());
                src.MPRICESHIP = System.Convert.ToDouble(src.dwVKP["MPRICESHIP"].ToString().Trim());
                src.MCOSTSHIP = System.Convert.ToDouble(src.dwVKP["MCOSTSHIP"].ToString().Trim());
                src.MPRICEFLIGHT = System.Convert.ToDouble(src.dwVKP["MPRICEFLIGHT"].ToString().Trim());
                src.MCOSTFLIGHT = System.Convert.ToDouble(src.dwVKP["MCOSTFLIGHT"].ToString().Trim());
                src.MCOSTADD = System.Convert.ToDouble(src.dwVKP["MCOSTADD"].ToString().Trim());
                src.STAFF = Helpers.Helper.Convert8859P1ToGB2312(src.dwVKP["HRNNAME"].ToString().Trim());

                src.txtCOLOR.Text = src.COLOR.ToString();
                src.txtYARN.Text = src.YARN.ToString();
                src.txtWEFTDEN.Text = src.WEFTDEN.ToString();
                src.txtWARPUSAGE.Text = src.WARPUSAGE.ToString();
                src.txtWARPPRICE.Text = src.WARPPRICE.ToString();
                src.txtWEFTUSAGE.Text = src.WEFTUSAGE.ToString();
                src.txtWEFTPRICE.Text = src.WEFTPRICE.ToString();
                src.txtYARNVALUE.Text = src.YARNVALUE.ToString();
                src.txtWARPED.Text = src.WARPED.ToString();
                src.txtWEFTED.Text = src.WEFTED.ToString();
                src.txtDYEVALUE.Text = src.DYEVALUE.ToString();
                src.txtCOSTFIN.Text = src.MCOSTFIN.ToString();
                src.txtCOSTPAKVV.Text = src.MCOSTPAKVV.ToString();
                src.txtCOSTFADD.Text = src.MCOSTFADD.ToString();
                src.txtAGENT.Text = src.MPRICEAGENT.ToString();
                src.txtSHIP.Text = src.MPRICESHIP.ToString();
                src.txtFLIGHT.Text = src.MPRICEFLIGHT.ToString();
                src.cmbCURRENCY.Text = "";
                src.cmbCURRENCY.Text = src.CURRENCY.ToString();
                src.txtPREH.Text = src.PREH.ToString();
                #endregion 
            }
            
        }
        #endregion
        public CollectionViewSource vwCOST
        {
            get
            {
                object source = this.TryFindResource("vwCOST"); 
            if (source == null)  return null; return (CollectionViewSource)source; 
            } 
        }
        VJLTCOST vm;
        VSDDAT VSDDAT;
        VICC_VKCOST VICC_VKCOST;
        VICC_VKPRICE VICC_VKPRICE;
        public JLTCOST()
        {
            vm = new VJLTCOST();
            DataContext = vm; 
            InitializeComponent();
            this.Name = "销售工交";
            if (app.User.Trim() == "JLTV")
            {
                ARTP = "J6-0220";
            } 

        }
        bool Isload = false,flag = false,load = false;
        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            try
            {
                if(Isload)
                {
                   
                }
                else
                {
                    FROM_DATE.Text = System.DateTime.Today.AddDays(0).Year.ToString()
                                     + "-" + System.DateTime.Today.AddDays(0).Month.ToString()
                                     + "-" + System.DateTime.Today.AddDays(0).Day.ToString();
                    FROMDATE = System.DateTime.Today.AddDays(0).Year.ToString()
                                + System.DateTime.Today.AddDays(0).Month.ToString().PadLeft(2, '0')
                                + System.DateTime.Today.AddDays(0).Day.ToString().PadLeft(2, '0');
                    DAT = System.DateTime.Today.AddDays(0).Year.ToString()
                                + System.DateTime.Today.AddDays(0).Month.ToString().PadLeft(2, '0')
                                + System.DateTime.Today.AddDays(0).Day.ToString().PadLeft(2, '0');
                    CURR = "USD";
                    cmbCURRENCY.Text = "USD";
                    cmbFACTORY.Text = "JL";                 
                    Isload = true;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void LOAD_RATE(object sender, RoutedEventArgs e)
        { 
            try
            {
                        VSDDAT=new VSDDAT();
                        DataRow dwData = VSDDAT.SetProd.Tables["SDDAT"].NewRow();
                        dwData["SDKEY"] = " AND SDKEY LIKE '00" + CURR + "%'";
                        dwData["SDSA"] = "0149";
                        DataSet SD = new DataSet();
                        SD = VSDDAT.QuerySDDAT(dwData, 149);
                        foreach(DataRow dw in SD.Tables["SDDAT"].Rows)
                        {
                            txtRATE.Text = dw["RATE"].ToString().Trim();
                        }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }
        private void FROM_DATE_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                FROMDATE = "";
                FROMDATE = Helpers.Helper.GetDate(sender);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }
        private void END_DATE_SelectedDateChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                ENDDATE = "";
                ENDDATE = Helpers.Helper.GetDate(sender);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }

        private void cmbCURRENCY_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                if (load) return;
                ComboBox cb = sender as ComboBox;
                if (cb.SelectedIndex == -1)
                    return;
                string CURRNEW =(string) (cb.SelectedItem as ComboBoxItem).Content;                
                CURR = CURRNEW;
                LOAD_RATE(null,null);
                txtVALUE.Focus();
                txtVALUE_TextChanged(null,null);
                
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }

        private bool CHECKDATA(object sender, RoutedEventArgs e)
        {
            try
            {
                if(VKPART=="")
                {
                    MessageBox.Show("请先选择上面业务员的核算记录！");
                    return false;
                }
                FACTORY = cmbFACTORY.Text.ToString().Trim();
                if(FACTORY=="")
                {
                    MessageBox.Show("公司不可为空！");
                    return false;
                }
                string v_weftden = txtWEFTDEN.Text.ToString().Trim();
                if (v_weftden==""||v_weftden=="0")
                {
                    MessageBox.Show("纬密不可为空！");
                    return false;
                }
                if (VKPART.ToUpper().Substring(0, 1) == "J")
                {
                    string v_yarnvalue = txtYARNVALUE.Text.ToString().Trim();
                    if (v_yarnvalue == "" || v_yarnvalue == "0")
                    {
                        MessageBox.Show("原料金额不可为空！");
                        return false;
                    }
                }
                if(FROMDATE=="")
                {
                    MessageBox.Show("请选择记帐日期！");
                    return false;
                }
                //if (ENDDATE == "")
                //{
                //    MessageBox.Show("请选择发货日期！");
                //    return false;
                //}
                string v_rate = txtRATE.Text.ToString().Trim();
                if (v_rate == "" || v_rate == "0")
                {
                    MessageBox.Show("汇率不可为空！");
                    return false;
                }
                string v_qtym = txtQTYM.Text.ToString().Trim();
                if (v_qtym == "" || v_qtym == "0")
                {
                    MessageBox.Show("数量不可为空！");
                    return false;
                }
                string v_value = txtVALUE.Text.ToString().Trim();
                if (v_value == ""||v_value=="0")
                {
                    MessageBox.Show("金额不可为空！");
                    return false;
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
            return true;
        }

        private void CALCUTE(object sender, RoutedEventArgs e)
        {
            try
            {
                string v_yarnvalue = txtYARNVALUE.Text.ToString().Trim();
                if (v_yarnvalue == "")
                {
                    v_yarnvalue = "0";
                }
                YARNVALUE = System.Convert.ToDouble(v_yarnvalue);
                string v_dyevalue = txtDYEVALUE.Text.ToString().Trim();
                if (v_dyevalue == "")
                {
                    v_dyevalue = "0";
                }
                DYEVALUE = System.Convert.ToDouble(v_dyevalue);
                string v_costfin = txtCOSTFIN.Text.ToString().Trim();
                if (v_costfin == "")
                {
                    v_costfin = "0";
                }
                MCOSTFIN = System.Convert.ToDouble(v_costfin);
                string v_costpakvv = txtCOSTPAKVV.Text.ToString().Trim();
                if (v_costpakvv == "")
                {
                    v_costpakvv = "0";
                }
                MCOSTPAKVV = System.Convert.ToDouble(v_costpakvv);
                string v_costfadd = txtCOSTFADD.Text.ToString().Trim();
                if (v_costfadd == "")
                {
                    v_costfadd = "0";
                }
                MCOSTFADD = System.Convert.ToDouble(v_costfadd);
                MCOSTUNIT = Helpers.Helper.RoundX( YARNVALUE + DYEVALUE + MCOSTFIN + MCOSTPAKVV + MCOSTFADD + MCOSTAGENT + MCOSTSHIP + MCOSTFLIGHT + MCOSTADD,100);
                
                WEFTDEN = System.Convert.ToDouble(txtWEFTDEN.Text.ToString().Trim());
                WEFTTOT = Helpers.Helper.RoundX(WEFTDEN * MDELQTY, 100);
                
                FACTORY = cmbFACTORY.Text.ToString().Trim();
                CURRENCY = cmbCURRENCY.Text.ToString().Trim();
                string VR = txtRATE.Text.ToString().Trim();
                if(VR=="") VR = "1";
                RATE = System.Convert.ToDouble(VR);
                RMBPRICE = Helpers.Helper.RoundX(PRICE * RATE*1.17, 100);
                MCOSTGROSS = Helpers.Helper.RoundX(RMBPRICE - MCOSTUNIT,100);
                MCOSTNET = Helpers.Helper.RoundX(MCOSTGROSS / 1.17, 100);
                COSTTOT = MDELQTY * MCOSTNET;
                COSTTOTW = Helpers.Helper.RoundX(MCOSTNET / WEFTDEN * 10000, 1);
                INVOICE = Helpers.Helper.ConvertGB2312To8859P1(txtINVOICE.Text.ToString().Trim());
                COMMISSION = Helpers.Helper.ConvertGB2312To8859P1(txtCOMMISSION.Text.ToString().Trim());
                NEWART = Helpers.Helper.ConvertGB2312To8859P1(txtNEW.Text.ToString().Trim());
                REMARK = Helpers.Helper.ConvertGB2312To8859P1(txtREMARK.Text.ToString().Trim());
                string v_prodvalue = txtPRODVALUE.Text.ToString().Trim();
                if(v_prodvalue == "")
                {
                    v_prodvalue = "0";
                }
                PRODVALUE = System.Convert.ToDouble(v_prodvalue);
                string v_othersvalue = txtOTHERSVALUE.Text.ToString().Trim();
                if(v_othersvalue == "")
                {
                    v_othersvalue = "0";
                }
                OTHERSVALUE = System.Convert.ToDouble(v_othersvalue);
                INVDAT = FROMDATE;
                DELDAT = ENDDATE;
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void QUERYICC_VKCOST(object sender, RoutedEventArgs e)
        {
            try
            {
                VICC_VKCOST = new VICC_VKCOST();
                DataRow DW = VICC_VKCOST.SetProd.Tables["ICC_VKCOST"].NewRow();
                DW["VKPART"] = ARTP.Trim();
                DataSet ICC_VKCOST = new DataSet();
                ICC_VKCOST = VICC_VKCOST.QueryICC_VKCOST(DW, 2);
                //dlgMaster.DataContext = ICC_VKCOST.Tables["ICC_VKCOST"];
                vwCOST.Source = ICC_VKCOST.Tables["ICC_VKCOST"];
                vwCOST.View.MoveCurrentTo(-1);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void RESET(object sender, RoutedEventArgs e)
        {
            try
            {
                END_DATE.Text = "";
                txtINVOICE.Text = "";
                txtQTYM.Text = "";
                txtQTYY.Text = "";
                txtPRICE.Text = "";
                txtVALUE.Text = "";
                txtCOMMISSION.Text = "";
                txtNEW.Text = "";
                txtPRODVALUE.Text = "";
                txtOTHERSVALUE.Text = "";
                txtCOLOR.Text = "";
                txtYARN.Text = "";
                txtWEFTDEN.Text = "";
                txtWARPUSAGE.Text = "";
                txtWARPPRICE.Text = "";
                txtWEFTUSAGE.Text = "";
                txtWEFTPRICE.Text = "";
                txtYARNVALUE.Text = "";
                txtWARPED.Text = "";
                txtWEFTED.Text = "";
                txtDYEVALUE.Text = "";
                txtCOSTFIN.Text = "";
                txtCOSTPAKVV.Text = "";
                txtCOSTFADD.Text = "";
                txtAGENT.Text = "";
                txtSHIP.Text = "";
                txtFLIGHT.Text = "";
                txtROWID.Text = "";
                FROM_DATE.Text = System.DateTime.Today.AddDays(0).Year.ToString()
                                     + "-" + System.DateTime.Today.AddDays(0).Month.ToString()
                                     + "-" + System.DateTime.Today.AddDays(0).Day.ToString();
                FROMDATE = System.DateTime.Today.AddDays(0).Year.ToString()
                            + System.DateTime.Today.AddDays(0).Month.ToString().PadLeft(2, '0')
                            + System.DateTime.Today.AddDays(0).Day.ToString().PadLeft(2, '0');
                DAT = System.DateTime.Today.AddDays(0).Year.ToString()
                            + System.DateTime.Today.AddDays(0).Month.ToString().PadLeft(2, '0')
                            + System.DateTime.Today.AddDays(0).Day.ToString().PadLeft(2, '0');
                CURR = "USD";
                cmbCURRENCY.Text = "USD";
                cmbFACTORY.Text = "JL";
                txtREMARK.Text = "";
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void btnINSERT_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtROWID.Text.ToString().Trim() != "")
                {
                    MessageBox.Show("不是新建数据，不可以点‘插入记录’按钮！");
                    return;
                }
                if (!CHECKDATA(null, null))
                    return;
                CALCUTE(null, null);                
                VICC_VKCOST = new VICC_VKCOST();
                DataSet VKCOST = new DataSet();
                VKCOST.Clear();
                VKCOST.AcceptChanges();
                VKCOST = VICC_VKCOST.QueryICC_VKCOST(null, 1);
                foreach (DataRow dw in VKCOST.Tables["ICC_VKCOST"].Rows)
                {
                    ROWNID = System.Convert.ToInt32(dw["ROWNID"].ToString().Trim());
                }
                DataRow dwData = VICC_VKCOST.SetProd.Tables["ICC_VKCOST"].NewRow();
                #region=====赋值========
                dwData["ROWNID"] = ROWNID;
                dwData["MANDANT"] = MANDANT;
                dwData["INVDAT"] = INVDAT;
                dwData["DELDAT"] = DELDAT;
                dwData["INVOICE"] = INVOICE;
                dwData["VKPAUFKRS"] = VKPAUFKRS;
                dwData["VKPAUFLFD"] = VKPAUFLFD;
                dwData["VKPKOLL"] = VKPKOLL;
                dwData["VKPART"] = VKPART;
                dwData["VAABEZ"] = Helpers.Helper.ConvertGB2312To8859P1(VAABEZ);
                dwData["CONSTRUCTION"] = Helpers.Helper.ConvertGB2312To8859P1(CONSTRUCTION.Replace("'","‘"));
                dwData["COLOR"] = COLOR;
                dwData["YARN"] = Helpers.Helper.ConvertGB2312To8859P1(YARN.Replace("'", "‘"));
                dwData["RATE"] = RATE;
                dwData["FACTORY"] = FACTORY;
                dwData["WARPDEN"] = WARPDEN;
                dwData["WEFTDEN"] = WEFTDEN;
                dwData["MKUNDER"] = MKUNDER;
                dwData["KDKNAME"] = Helpers.Helper.ConvertGB2312To8859P1(KDKNAME);
                dwData["VKPQTY"] = VKPQTY;
                dwData["TYPE"] = TYPE;
                dwData["CURRENCY"] = CURRENCY;
                dwData["PREH"] = PREH;
                dwData["MDELQTY"] = MDELQTY;
                dwData["YDELQTY"] = YDELQTY;
                dwData["WEFTTOT"] = WEFTTOT;
                dwData["WARPUSAGE"] = WARPUSAGE;
                dwData["WARPPRICE"] = WARPPRICE;
                dwData["WEFTUSAGE"] = WEFTUSAGE;
                dwData["WEFTPRICE"] = WEFTPRICE;
                dwData["YARNVALUE"] = YARNVALUE;
                dwData["WARPED"] = WARPED;
                dwData["WEFTED"] = WEFTED;
                dwData["DYEVALUE"] = DYEVALUE;
                dwData["MCOSTFIN"] = MCOSTFIN;
                dwData["MCOSTPAKVV"] = MCOSTPAKVV;
                dwData["MCOSTFADD"] = MCOSTFADD;
                dwData["MPRICEAGENT"] = MPRICEAGENT;
                dwData["MCOSTAGENT"] = MCOSTAGENT;
                dwData["MPRICESHIP"] = MPRICESHIP;
                dwData["MCOSTSHIP"] = MCOSTSHIP;
                dwData["MPRICEFLIGHT"] = MPRICEFLIGHT;
                dwData["MCOSTFLIGHT"] = MCOSTFLIGHT;
                dwData["MCOSTADD"] = MCOSTADD;
                dwData["MCOSTUNIT"] = MCOSTUNIT;
                dwData["RMBPRICE"] = RMBPRICE;
                dwData["MCOSTGROSS"] = MCOSTGROSS;
                dwData["MCOSTNET"] = MCOSTNET;
                dwData["COSTTOT"] = COSTTOT;
                dwData["COSTTOTW"] = COSTTOTW;
                dwData["STAFF"] = Helpers.Helper.ConvertGB2312To8859P1(STAFF);
                dwData["COMMISSION"] = COMMISSION;
                dwData["NEWART"] = NEWART;
                dwData["PRICE"] = PRICE;
                dwData["INVVALUE"] = INVVALUE;
                dwData["RMBVALUE"] = RMBVALUE;
                dwData["REMARK"] = REMARK;
                dwData["PRODVALUE"] = PRODVALUE;
                dwData["OTHERSVALUE"] = OTHERSVALUE;
                dwData["NM1"] = 0;
                dwData["NM2"] = 0;
                dwData["NM3"] = 0;
                dwData["NM4"] = 0;
                dwData["NM5"] = 0;
                dwData["CHAR1"] = "";
                dwData["CHAR2"] = "";
                dwData["CHAR3"] = "";
                dwData["CHAR4"] = "";
                dwData["CHAR5"] = "";
                dwData["NEWUSER"] = app.User;
                dwData["NEWTIME"] = DAT;
                dwData["CHGUSER"] = "";
                dwData["CHGTIME"] = "";
                #endregion
                VICC_VKCOST.InsertICC_VKCOST(dwData,"JLT");
                ART = ARTP;
                ARTP = "J5";
                ARTP = ART;
                //QUERYICC_VKCOST(null, null);
                //RESET(null, null);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void btnUPDATE_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtROWID.Text.ToString().Trim() == "")
                {
                    MessageBox.Show("请先在下面选择修改的记录！");
                    return;
                }
                if (!CHECKDATA(null, null))
                    return;
                CALCUTE(null, null);
                DataRow dwData = VICC_VKCOST.SetProd.Tables["ICC_VKCOST"].NewRow();
                #region=====赋值========
                dwData["ROWNID"] = ROWNID;
                dwData["INVDAT"] = INVDAT;
                dwData["DELDAT"] = DELDAT;
                dwData["INVOICE"] = INVOICE;
                dwData["RATE"] = RATE;
                dwData["FACTORY"] = FACTORY;
                dwData["WEFTDEN"] = WEFTDEN;
                dwData["CURRENCY"] = CURRENCY;
                dwData["MDELQTY"] = MDELQTY;
                dwData["YDELQTY"] = YDELQTY;
                dwData["WEFTTOT"] = WEFTTOT;
                dwData["WARPUSAGE"] = WARPUSAGE;
                dwData["WARPPRICE"] = WARPPRICE;
                dwData["WEFTUSAGE"] = WEFTUSAGE;
                dwData["WEFTPRICE"] = WEFTPRICE;
                dwData["YARNVALUE"] = YARNVALUE;
                dwData["WARPED"] = WARPED;
                dwData["WEFTED"] = WEFTED;
                dwData["DYEVALUE"] = DYEVALUE;
                dwData["MCOSTFIN"] = MCOSTFIN;
                dwData["MCOSTPAKVV"] = MCOSTPAKVV;
                dwData["MCOSTFADD"] = MCOSTFADD;
                dwData["MPRICEAGENT"] = MPRICEAGENT;
                dwData["MCOSTAGENT"] = MCOSTAGENT;
                dwData["MPRICESHIP"] = MPRICESHIP;
                dwData["MCOSTSHIP"] = MCOSTSHIP;
                dwData["MPRICEFLIGHT"] = MPRICEFLIGHT;
                dwData["MCOSTFLIGHT"] = MCOSTFLIGHT;
                dwData["MCOSTADD"] = MCOSTADD;
                dwData["MCOSTUNIT"] = MCOSTUNIT;
                dwData["RMBPRICE"] = RMBPRICE;
                dwData["MCOSTGROSS"] = MCOSTGROSS;
                dwData["MCOSTNET"] = MCOSTNET;
                dwData["COSTTOT"] = COSTTOT;
                dwData["COSTTOTW"] = COSTTOTW;
                dwData["COMMISSION"] = COMMISSION;
                dwData["NEWART"] = NEWART;
                dwData["PRICE"] = PRICE;
                dwData["INVVALUE"] = INVVALUE;
                dwData["RMBVALUE"] = RMBVALUE;
                dwData["REMARK"] = REMARK;
                dwData["PRODVALUE"] = PRODVALUE;
                dwData["OTHERSVALUE"] = OTHERSVALUE;
                dwData["CHGUSER"] = app.User;
                dwData["CHGTIME"] = DAT;
                #endregion
                VICC_VKCOST.UpdateICC_VKCOST(dwData, "JLT");
                QUERYICC_VKCOST(null, null);
                RESET(null, null);
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void btnDELETE_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                if (txtROWID.Text.ToString().Trim() == "")
                {
                    MessageBox.Show("请先在下面选择需要删除的记录！");
                    return;
                }
                string v_sign = txtSIGN.Text.ToString().Trim().ToUpper();
                if(v_sign!="Y")
                {
                    MessageBox.Show("为防止错误删除，请先将删除标志改为Y，才可以进行删除！");
                    return;
                }
                DataRow dwData = VICC_VKCOST.SetProd.Tables["ICC_VKCOST"].NewRow();
                dwData["ROWNID"] = ROWNID;
                VICC_VKCOST.DeleteICC_VKCOST(dwData,1);
                QUERYICC_VKCOST(null, null);
                RESET(null, null);
                txtSIGN.Text = "N";
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void txtQTYM_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
             {
                 if (load) return;
                if(txtQTYM.IsFocused||flag)
                {
                    string v_qtym = txtQTYM.Text.ToString().Trim();
                    if(v_qtym=="")
                    {
                        v_qtym = "0";
                    }
                     MDELQTY = System.Convert.ToDouble(v_qtym);                 
                     YDELQTY = Helpers.Helper.RoundX(MDELQTY/0.9144,100) ;
                     txtQTYY.Text = YDELQTY.ToString();
                     string v_value = txtVALUE.Text.ToString().Trim();
                     if (v_value=="")
                    {
                        v_value = "0";
                    }
                     INVVALUE = System.Convert.ToDouble(v_value);                 
                     if(MDELQTY ==0 ||INVVALUE==0)
                     {
                         PRICE = 0;
                     }
                     else
                     {                     
                         PRICE = Helpers.Helper.RoundX(INVVALUE / MDELQTY, 100);
                     }
                     txtPRICE.Text = PRICE.ToString();
                 
                }
                 
                 
             }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void txtQTYY_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (load) return;
                if (txtQTYY.IsFocused)
                {
                    string v_qtyy = txtQTYY.Text.ToString().Trim();
                    if(v_qtyy=="")
                    {
                        v_qtyy = "0";
                    }
                    YDELQTY = System.Convert.ToDouble(v_qtyy);                
                    MDELQTY = Helpers.Helper.RoundX(YDELQTY * 0.9144, 100);
                    txtQTYM.Text = MDELQTY.ToString();
                    string v_value = txtVALUE.Text.ToString().Trim();
                    if (v_value == "")
                    {
                        v_value = "0";
                    }
                    INVVALUE = System.Convert.ToDouble(v_value);                 
                    if (MDELQTY == 0 || INVVALUE == 0)
                    {
                        PRICE = 0;
                    }
                    else
                    {
                        PRICE = Helpers.Helper.RoundX(INVVALUE / MDELQTY, 100);
                    }
                    txtPRICE.Text = PRICE.ToString();
                }
                

            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void txtVALUE_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (load) return;
                if (txtVALUE.IsFocused || flag)
                {
                    string v_qtym = txtQTYM.Text.ToString().Trim();
                    if (v_qtym == "")
                    {
                        v_qtym = "0";
                    }
                    MDELQTY = System.Convert.ToDouble(v_qtym);
                    string v_value = txtVALUE.Text.ToString().Trim();
                    if (v_value == "")
                    {
                        v_value = "0";
                    }
                    INVVALUE = System.Convert.ToDouble(v_value);
                    string v_rate = txtRATE.Text.ToString().Trim();
                    if (v_rate == "")
                    {
                        v_rate = "0";
                    }
                    RATE = System.Convert.ToDouble(v_rate);
                    if (MDELQTY == 0 || INVVALUE == 0)
                    {
                        PRICE = 0;
                    }
                    else
                    {
                        PRICE = Helpers.Helper.RoundX(INVVALUE / MDELQTY, 100);
                    }
                    txtPRICE.Text = PRICE.ToString();
                    if (RATE == 0 || INVVALUE == 0)
                    {
                        RMBVALUE = 0;
                    }
                    else
                    {
                        RMBVALUE = Helpers.Helper.RoundX(INVVALUE * RATE, 100);
                    }
                }
                
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void YARNCOST(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (load) return;
                if (txtWARPUSAGE.IsFocused || txtWARPPRICE.IsFocused || txtWEFTUSAGE.IsFocused || txtWEFTPRICE.IsFocused || txtWARPED.IsFocused || txtWEFTED.IsFocused)
                {
                    string v_warpusage = txtWARPUSAGE.Text.ToString().Trim();
                    if (v_warpusage == "")
                    {
                        v_warpusage = "0";
                    }
                    WARPUSAGE = System.Convert.ToDouble(v_warpusage);
                    string v_warpprice = txtWARPPRICE.Text.ToString().Trim();
                    if (v_warpprice == "")
                    {
                        v_warpprice = "0";
                    }
                    WARPPRICE = System.Convert.ToDouble(v_warpprice);
                    string v_weftusage = txtWEFTUSAGE.Text.ToString().Trim();
                    if (v_weftusage == "")
                    {
                        v_weftusage = "0";
                    }
                    WEFTUSAGE = System.Convert.ToDouble(v_weftusage);
                    string v_weftprice = txtWEFTPRICE.Text.ToString().Trim();
                    if (v_weftprice == "")
                    {
                        v_weftprice = "0";
                    }
                    WEFTPRICE = System.Convert.ToDouble(v_weftprice);
                    YARNVALUE = Helpers.Helper.RoundX(WARPUSAGE * WARPPRICE + WEFTUSAGE * WEFTPRICE, 100);
                    txtYARNVALUE.Text = YARNVALUE.ToString();
                    string v_warped = txtWARPED.Text.ToString().Trim();
                    if (v_warped == "")
                    {
                        v_warped = "0";
                    }
                    WARPED = System.Convert.ToDouble(v_warped);
                    string v_wefted = txtWEFTED.Text.ToString().Trim();
                    if (v_wefted == "")
                    {
                        v_wefted = "0";
                    }
                    WEFTED = System.Convert.ToDouble(v_wefted);
                    DYEVALUE = Helpers.Helper.RoundX(WARPUSAGE * WARPED + WEFTUSAGE * WEFTED, 100);
                    txtDYEVALUE.Text = DYEVALUE.ToString();
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void txtAGENT_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (load) return;
                if (txtAGENT.IsFocused || flag)
                {
                    if (CURRENCY == "" || PREH == "")
                    {
                        MessageBox.Show("请先选择上面业务员的核算记录！");
                        return;
                    }
                    string v_agent = txtAGENT.Text.ToString().Trim();
                    if (v_agent == "")
                    {
                        v_agent = "0";
                    }
                    MPRICEAGENT = System.Convert.ToDouble(v_agent);
                    if (CURRENCY != "RMB")
                    {
                        MCOSTAGENT = MPRICEAGENT * RATE;
                    }
                    if (PREH == "YRD")
                    {
                        MCOSTAGENT = MCOSTAGENT / 0.9144;
                    }
                    MCOSTAGENT = Helpers.Helper.RoundX(MCOSTAGENT * 0.01 * 0.99 * 1.17, 100);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void txtSHIP_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (load) return;
                if (txtSHIP.IsFocused || flag)
                {
                    if (CURRENCY == "" || PREH == "")
                    {
                        MessageBox.Show("请先选择上面业务员的核算记录！");
                        return;
                    }
                    string v_ship = txtSHIP.Text.ToString().Trim();
                    if (v_ship == "")
                    {
                        v_ship = "0";
                    }
                    MPRICESHIP = System.Convert.ToDouble(v_ship);
                    if (CURRENCY != "RMB")
                    {
                        MCOSTSHIP = MPRICESHIP * RATE;
                    }
                    if (PREH == "YRD")
                    {
                        MCOSTSHIP = MCOSTSHIP / 0.9144;
                    }
                    MCOSTSHIP = Helpers.Helper.RoundX(MCOSTSHIP * 0.01 * 0.99 * 1.17, 100);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void txtFLIGHT_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (load) return;
                if (txtFLIGHT.IsFocused || flag)
                {
                    if (CURRENCY == "" || PREH == "")
                    {
                        MessageBox.Show("请先选择上面业务员的核算记录！");
                        return;
                    }
                    string v_flight = txtFLIGHT.Text.ToString().Trim();
                    if (v_flight == "")
                    {
                        v_flight = "0";
                    }
                    MPRICEFLIGHT = System.Convert.ToDouble(v_flight);
                    if (CURRENCY != "RMB")
                    {
                        MCOSTFLIGHT = MPRICEFLIGHT * RATE;
                    }
                    if (PREH == "YRD")
                    {
                        MCOSTFLIGHT = MCOSTFLIGHT / 0.9144;
                    }
                    MCOSTFLIGHT = Helpers.Helper.RoundX(MCOSTFLIGHT * 0.01 * 0.99 * 1.17, 100);
                }
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }

        private void txtRATE_TextChanged(object sender, TextChangedEventArgs e)
        {
            try
            {
                if (load) return;

                string v_qty = txtQTYM.Text.ToString().Trim();
                if (v_qty != "" && v_qty != "0")
                {
                    flag = true;
                    txtQTYM_TextChanged(null,null);
                    txtVALUE_TextChanged(null,null);
                    txtAGENT_TextChanged(null,null);
                    txtSHIP_TextChanged(null, null);
                    txtFLIGHT_TextChanged(null, null);
                    flag = false;
                }
                
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }

        }

        private void dlgMaster_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                cVKP.vwMaster.View.MoveCurrentTo(-1);
                    DataRow dwICC_VKCOST;
                    if (e.AddedItems.Count == 0)
                    {
                        RESET(null,null);
                        return;
                    }
                    DataRowView drv = e.AddedItems[0] as DataRowView;
                    if (drv.Row == null)
                        return;
                    dwICC_VKCOST = drv.Row;
                    load = true;
                    #region====给变量赋值=====
                    ROWNID = System.Convert.ToInt32(dwICC_VKCOST["ROWNID"].ToString().Trim());
                    VKPART = dwICC_VKCOST["VKPART"].ToString().Trim();
                    INVDAT = dwICC_VKCOST["INVDAT"].ToString().Trim();
                    DELDAT = dwICC_VKCOST["DELDAT"].ToString().Trim();
                    INVOICE = dwICC_VKCOST["INVOICE"].ToString().Trim();
                    //VAABEZ = Helpers.Helper.Convert8859P1ToGB2312(dwICC_VKCOST["VKPART"].ToString().Trim());
                    COLOR = dwICC_VKCOST["COLOR"].ToString().Trim();
                    YARN = Helpers.Helper.Convert8859P1ToGB2312(dwICC_VKCOST["YARN"].ToString().Trim());
                    RATE = System.Convert.ToDouble(dwICC_VKCOST["RATE"].ToString().Trim());
                    RAT = System.Convert.ToDouble(dwICC_VKCOST["RATE"].ToString().Trim());
                    FACTORY = dwICC_VKCOST["FACTORY"].ToString().Trim();
                    WEFTDEN = System.Convert.ToDouble(dwICC_VKCOST["WEFTDEN"].ToString().Trim());
                    CURRENCY = dwICC_VKCOST["CURRENCY"].ToString().Trim();
                    PREH = dwICC_VKCOST["PREH"].ToString().Trim();
                    MDELQTY = System.Convert.ToDouble(dwICC_VKCOST["MDELQTY"].ToString().Trim());
                    YDELQTY = System.Convert.ToDouble(dwICC_VKCOST["YDELQTY"].ToString().Trim());
                    WEFTTOT = System.Convert.ToDouble(dwICC_VKCOST["WEFTTOT"].ToString().Trim());
                    WARPUSAGE = System.Convert.ToDouble(dwICC_VKCOST["WARPUSAGE"].ToString().Trim());
                    WARPPRICE = System.Convert.ToDouble(dwICC_VKCOST["WARPPRICE"].ToString().Trim());
                    WEFTUSAGE = System.Convert.ToDouble(dwICC_VKCOST["WEFTUSAGE"].ToString().Trim());
                    WEFTPRICE = System.Convert.ToDouble(dwICC_VKCOST["WEFTPRICE"].ToString().Trim());
                    YARNVALUE = System.Convert.ToDouble(dwICC_VKCOST["YARNVALUE"].ToString().Trim());
                    WARPED = System.Convert.ToDouble(dwICC_VKCOST["WARPED"].ToString().Trim());
                    WEFTED = System.Convert.ToDouble(dwICC_VKCOST["WEFTED"].ToString().Trim());
                    DYEVALUE = System.Convert.ToDouble(dwICC_VKCOST["DYEVALUE"].ToString().Trim());
                    MCOSTFIN = System.Convert.ToDouble(dwICC_VKCOST["MCOSTFIN"].ToString().Trim());
                    MCOSTPAKVV = System.Convert.ToDouble(dwICC_VKCOST["MCOSTPAKVV"].ToString().Trim());
                    MCOSTFADD = System.Convert.ToDouble(dwICC_VKCOST["MCOSTFADD"].ToString().Trim());
                    MPRICEAGENT = System.Convert.ToDouble(dwICC_VKCOST["MPRICEAGENT"].ToString().Trim());
                    MCOSTAGENT = System.Convert.ToDouble(dwICC_VKCOST["MCOSTAGENT"].ToString().Trim());
                    MPRICESHIP = System.Convert.ToDouble(dwICC_VKCOST["MPRICESHIP"].ToString().Trim());
                    MCOSTSHIP = System.Convert.ToDouble(dwICC_VKCOST["MCOSTSHIP"].ToString().Trim());
                    MPRICEFLIGHT = System.Convert.ToDouble(dwICC_VKCOST["MPRICEFLIGHT"].ToString().Trim());
                    MCOSTFLIGHT = System.Convert.ToDouble(dwICC_VKCOST["MCOSTFLIGHT"].ToString().Trim());
                    MCOSTADD = System.Convert.ToDouble(dwICC_VKCOST["MCOSTADD"].ToString().Trim());
                    MCOSTUNIT = System.Convert.ToDouble(dwICC_VKCOST["MCOSTUNIT"].ToString().Trim());
                    RMBPRICE = System.Convert.ToDouble(dwICC_VKCOST["RMBPRICE"].ToString().Trim());
                    MCOSTGROSS = System.Convert.ToDouble(dwICC_VKCOST["MCOSTGROSS"].ToString().Trim());
                    MCOSTNET = System.Convert.ToDouble(dwICC_VKCOST["MCOSTNET"].ToString().Trim());
                    COSTTOT = System.Convert.ToDouble(dwICC_VKCOST["COSTTOT"].ToString().Trim());
                    COSTTOTW = System.Convert.ToDouble(dwICC_VKCOST["COSTTOTW"].ToString().Trim());
                    COMMISSION = Helpers.Helper.Convert8859P1ToGB2312(dwICC_VKCOST["COMMISSION"].ToString().Trim());
                    NEWART = Helpers.Helper.Convert8859P1ToGB2312(dwICC_VKCOST["NEWART"].ToString().Trim());
                    PRICE = System.Convert.ToDouble(dwICC_VKCOST["PRICE"].ToString().Trim());
                    INVVALUE = System.Convert.ToDouble(dwICC_VKCOST["INVVALUE"].ToString().Trim());
                    RMBVALUE = System.Convert.ToDouble(dwICC_VKCOST["RMBVALUE"].ToString().Trim());
                    REMARK = Helpers.Helper.Convert8859P1ToGB2312(dwICC_VKCOST["REMARK"].ToString().Trim());
                    PRODVALUE = System.Convert.ToDouble(dwICC_VKCOST["PRODVALUE"].ToString().Trim());
                    OTHERSVALUE = System.Convert.ToDouble(dwICC_VKCOST["OTHERSVALUE"].ToString().Trim());
                    #endregion
                    #region====界面字段赋值=====
                    txtROWID.Text = ROWNID.ToString();
                    if (INVDAT != "")
                    {
                        FROM_DATE.Text = INVDAT.Substring(0, 4) + "-" + INVDAT.Substring(4, 2) + "-" + INVDAT.Substring(6, 2);
                    }
                    if (DELDAT != "")
                    {
                        END_DATE.Text = DELDAT.Substring(0, 4) + "-" + DELDAT.Substring(4, 2) + "-" + DELDAT.Substring(6, 2);
                    }                    
                    txtINVOICE.Text = INVOICE.ToString();
                    txtCOLOR.Text = COLOR.ToString();
                    txtYARN.Text = YARN.ToString();
                    txtRATE.Text = RATE.ToString();
                    cmbFACTORY.Text = FACTORY.ToString();
                    txtWEFTDEN.Text = WEFTDEN.ToString();
                    txtPREH.Text = PREH.ToString();
                    txtQTYM.Text = MDELQTY.ToString();
                    txtQTYY.Text = YDELQTY.ToString();
                    txtWARPUSAGE.Text = WARPUSAGE.ToString();
                    txtWARPPRICE.Text = WARPPRICE.ToString();
                    txtWEFTUSAGE.Text = WEFTUSAGE.ToString();
                    txtWEFTPRICE.Text = WEFTPRICE.ToString();
                    txtYARNVALUE.Text = YARNVALUE.ToString();
                    txtWARPED.Text = WARPED.ToString();
                    txtWEFTED.Text = WEFTED.ToString();
                    txtDYEVALUE.Text = DYEVALUE.ToString();
                    txtCOSTFIN.Text = MCOSTFIN.ToString();
                    txtCOSTPAKVV.Text = MCOSTPAKVV.ToString();
                    txtCOSTFADD.Text = MCOSTFADD.ToString();
                    txtAGENT.Text = MPRICEAGENT.ToString();
                    txtSHIP.Text = MPRICESHIP.ToString();
                    txtFLIGHT.Text = MPRICEFLIGHT.ToString();
                    txtCOMMISSION.Text = COMMISSION.ToString();
                    txtNEW.Text = NEWART.ToString();
                    txtPRICE.Text = PRICE.ToString();
                    txtVALUE.Text = INVVALUE.ToString();
                    txtREMARK.Text = REMARK.ToString();
                    txtPRODVALUE.Text = PRODVALUE.ToString();
                    txtOTHERSVALUE.Text = OTHERSVALUE.ToString();
                    cmbCURRENCY.Text = CURRENCY.ToString();
                    #endregion
                    load = false;
                
            }
            catch (Exception ex)
            {
                Tracer.Error(ex.StackTrace, ex);
            }
        }


    }
}